﻿using System;
using UnityEngine.Rendering;

namespace UnityEngine.PostProcessing
{
	// Token: 0x020000C5 RID: 197
	public sealed class FogComponent : PostProcessingComponentCommandBuffer<FogModel>
	{
		// Token: 0x170000AF RID: 175
		// (get) Token: 0x06000468 RID: 1128 RVA: 0x0002470F File Offset: 0x0002290F
		public override bool active
		{
			get
			{
				return base.model.enabled && this.context.isGBufferAvailable && RenderSettings.fog && !this.context.interrupted;
			}
		}

		// Token: 0x06000469 RID: 1129 RVA: 0x0002474C File Offset: 0x0002294C
		public override string GetName()
		{
			return "Fog";
		}

		// Token: 0x0600046A RID: 1130 RVA: 0x00003781 File Offset: 0x00001981
		public override DepthTextureMode GetCameraFlags()
		{
			return DepthTextureMode.Depth;
		}

		// Token: 0x0600046B RID: 1131 RVA: 0x00024753 File Offset: 0x00022953
		public override CameraEvent GetCameraEvent()
		{
			return CameraEvent.AfterImageEffectsOpaque;
		}

		// Token: 0x0600046C RID: 1132 RVA: 0x00024758 File Offset: 0x00022958
		public override void PopulateCommandBuffer(CommandBuffer cb)
		{
			FogModel.Settings settings = base.model.settings;
			Material material = this.context.materialFactory.Get("Hidden/Post FX/Fog");
			material.shaderKeywords = null;
			Color value = (!GraphicsUtils.isLinearColorSpace) ? RenderSettings.fogColor : RenderSettings.fogColor.linear;
			material.SetColor(FogComponent.Uniforms._FogColor, value);
			material.SetFloat(FogComponent.Uniforms._Density, RenderSettings.fogDensity);
			material.SetFloat(FogComponent.Uniforms._Start, RenderSettings.fogStartDistance);
			material.SetFloat(FogComponent.Uniforms._End, RenderSettings.fogEndDistance);
			FogMode fogMode = RenderSettings.fogMode;
			if (fogMode != FogMode.Linear)
			{
				if (fogMode != FogMode.Exponential)
				{
					if (fogMode == FogMode.ExponentialSquared)
					{
						material.EnableKeyword("FOG_EXP2");
					}
				}
				else
				{
					material.EnableKeyword("FOG_EXP");
				}
			}
			else
			{
				material.EnableKeyword("FOG_LINEAR");
			}
			RenderTextureFormat format = (!this.context.isHdr) ? RenderTextureFormat.Default : RenderTextureFormat.DefaultHDR;
			cb.GetTemporaryRT(FogComponent.Uniforms._TempRT, this.context.width, this.context.height, 24, FilterMode.Bilinear, format);
			cb.Blit(BuiltinRenderTextureType.CameraTarget, FogComponent.Uniforms._TempRT);
			cb.Blit(FogComponent.Uniforms._TempRT, BuiltinRenderTextureType.CameraTarget, material, (!settings.excludeSkybox) ? 0 : 1);
			cb.ReleaseTemporaryRT(FogComponent.Uniforms._TempRT);
		}

		// Token: 0x040005DE RID: 1502
		private const string k_ShaderString = "Hidden/Post FX/Fog";

		// Token: 0x020000C6 RID: 198
		private static class Uniforms
		{
			// Token: 0x040005DF RID: 1503
			internal static readonly int _FogColor = Shader.PropertyToID("_FogColor");

			// Token: 0x040005E0 RID: 1504
			internal static readonly int _Density = Shader.PropertyToID("_Density");

			// Token: 0x040005E1 RID: 1505
			internal static readonly int _Start = Shader.PropertyToID("_Start");

			// Token: 0x040005E2 RID: 1506
			internal static readonly int _End = Shader.PropertyToID("_End");

			// Token: 0x040005E3 RID: 1507
			internal static readonly int _TempRT = Shader.PropertyToID("_TempRT");
		}
	}
}
